package dao

import (
	"golang.org/x/net/context"
	"sale-admin/internal/dal"
)

type IMaActivityFilter interface {
	fmtFilter(ctx context.Context, tx dal.IMaActivityDo, q *dal.Query) dal.IMaActivityDo
}

var _ IMaActivityFilter = (*MaActivityFilter)(nil)

type MaActivityFilter struct {
	ID       string
	NickName string
	Gender   *int
	Deleted  *bool
}

// 筛选器
func (p *MaActivityFilter) fmtFilter(ctx context.Context, tx dal.IMaActivityDo, q *dal.Query) dal.IMaActivityDo {
	if p.ID != "" {
		tx = tx.Where(q.MaActivity.ID.Eq(p.ID))
	}

	return tx
}

type MaActivityListFilter struct {
	ID       string
	NickName string
	Gender   *int
	Deleted  *int
}

func (p *MaActivityListFilter) fmtFilter(ctx context.Context, tx dal.IMaActivityDo, q *dal.Query) dal.IMaActivityDo {
	if p.ID != "" {
		tx = tx.Where(q.MaActivity.ID.Eq(p.ID))
	}

	if p.Deleted != nil {
		tx = tx.Where(q.MaActivity.Deleted.Eq(*p.Deleted))
	} else {
		//默认只查询未被删除的
		tx = tx.Where(q.MaActivity.Deleted.Eq(0))
	}

	return tx
}
